package cn.smbms.tools;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

public class ConfigManager {
	private static ConfigManager configManager;
	private static Properties properties;
	
	private ConfigManager() {
		String configFile = "database.properties";
		properties = new Properties();
		InputStream is = ConfigManager.class.getClassLoader().getResourceAsStream(configFile);
		try {
			properties.load(is);
			is.close();
		} catch (IOException e) {
			// TODO: handle exception
			e.printStackTrace();
		}
	}
/*	
	//全局访问点		懒汉模式
	public static synchronized ConfigManager getInstance() {
		if (configManager == null) {
			configManager = new ConfigManager();
		}
		return configManager;
	}*/
	//全局访问点	饿汉模式
		public static ConfigManager getInstance() {
			if (configManager == null) {
				configManager = new ConfigManager();
			}
			return configManager;
		}
	
	public String getValue(String key) {
		return properties.getProperty(key);
	}
	public static void main(String[] args) {
		ConfigManager config = new ConfigManager();
		String str =ConfigManager .getInstance().getValue("username");
		System.out.println(str);
	}
	
 
}
